package second.group.bering.parking_system

import second.group.bering.parking_system.model.Car;
/**
 *
 * ParkingBoy
 *
 * @author Burgess Li, Thomas Chen
 * @date 8/23/2018 4:44 PM
 * @version 1.0
 *
 */
class ParkingBoy {

    Map<String, Park> parks = [:]

    boolean addPark(Park park) {
        if (park && !parks[park.id]) {
            parks[park.id] = park
            return true
        }
        return false
    }

    /**
     * Task #3
     * @param car
     * @return park id
     */
    String parking(Car car) {
        if (car && parks.values().any { it.hasLocation() }) {
            Park park = parks.values().find { it.hasLocation() }
            park.parking(car)
            return park.id
        }
        return null
    }

    /**
     * Task #4
     * @param parkId
     * @param carNumber
     * @return car
     */
    Car pickup(String parkId, String carNumber) {
        if (parkId && carNumber && parks[parkId] && parks[parkId].hasCar(carNumber)) {
            return parks[parkId].pickup(carNumber)
        }
        return null
    }

}
